#define _CRT_SECURE_NO_WARNINGS 1
/*
// Definition for a Node.
class Node {
public:
    int val;
    vector<Node*> children;

    Node() {}

    Node(int _val) {
        val = _val;
    }

    Node(int _val, vector<Node*> _children) {
        val = _val;
        children = _children;
    }
};
*/

class Solution {
public:
    vector<vector<int>> levelOrder(Node* root) {
        vector<vector<int>> ret;
        if (root == nullptr)
            return ret;
        queue<Node*> q;
        q.push(root);
        while (!q.empty())
        {
            int count = q.size();
            vector<int> arr;
            while (count--)
            {
                arr.push_back(q.front()->val);
                for (auto n : q.front()->children)
                {
                    q.push(n);
                }
                q.pop();
            }
            ret.push_back(arr);
        }
        return ret;
    }
};